package com.gepengjun.lims.config.shiro.filter;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.gepengjun.lims.entity.Permission;
import com.gepengjun.lims.service.PermissionService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

public class ShiroUrlUtil {

    @Autowired
    private PermissionService permissionService;

    public  Map<String,String> getFilterChainDefinitionMap(){
        Map<String,String> filterChainDefinitionMap = new LinkedHashMap<>();
        filterChainDefinitionMap.put("/static/**", "anon");
        filterChainDefinitionMap.put("/css/**", "anon");
        filterChainDefinitionMap.put("/assets/**", "anon");
        filterChainDefinitionMap.put("/js/**", "anon");
        filterChainDefinitionMap.put("/logout", "logout");
        filterChainDefinitionMap.put("/kaptcha", "anon");
        filterChainDefinitionMap.put("/favicon.ico", "anon");
        filterChainDefinitionMap.put("/login", "kaptcha");

        List<Permission> permissionList = permissionService.selectList(new EntityWrapper<>());
        for (Permission permission:permissionList){
            if (StringUtils.isNotEmpty(permission.getUrl())){
                filterChainDefinitionMap.put(permission.getUrl(),"kickout,user,perms["+permission.getPermissionStr()+"]");
            }
        }
        filterChainDefinitionMap.put("/**", "kickout,user");
        return filterChainDefinitionMap;
    }


}
